const $$$ = (function () {
    const getParmas = (data) => {
        let str = "";
        for (let key in data) {
            str += key + "=" + data[key] + "&"
        }
        return str;
    }

    const jsonp = (setting) => {
        //函数先定义后使用
        return new Promise((resolve, reject) => {
            //1. 随机生成一个函数 
            let fnName = "jq_" + parseInt(Math.random() * 20);
            window[fnName] = resolve;
            //2.拼接请求路径
            let newUrl = setting.url + "?" + getParmas(setting.data) + setting.callbackName + "=" + fnName;
            //3.创建一个script标签
            let oScript = document.createElement("script");
            document.body.appendChild(oScript);
            oScript.src = newUrl;
            //访问完后后 删除script
            //凡是带有src属性的 都有一个onload事件
            oScript.onload = () => {
                oScript.remove()
            }
        })
    }
    return {jsonp}
})()